
/*批改精品申请*/
function factory (BetterArticleModel, ArticleModel, UserModel) {
  return function (req, res) {
    /*
      请求体： {applyId: apply._id, isPass: 1}
    */

    var body = req.body
    BetterArticleModel.findOne({_id: body.applyId}, function (err, apply) {
      if (apply.status.checked) {
        res.send('0')
      }else {
        apply.status.isPass = body.isPass
        apply.status.checked = 1
        apply.save(function (err, apply) {
          var articleId = apply.articleId
          /*这俩可以并行*/
          ArticleModel.update({_id: articleId}, {$set: {better: 1}}, function (err, r) {
            UserModel.findOne({user: apply.articleAutor}, function (err, user) {
              console.log(user)
              user.integral += 20
              user.save(function (err, user) {
                res.send('1')
              })
            })
          })
        })
      }
    })
  }
}

module.exports = factory